﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Theoreme.Teaching.AOP.Sample01
{
    public class Test_Tracing
    {
        public static void Run()
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            Method1();
            Factorial(5);
            Factorial(-5);
        }


        /***************************************************************************************************
         *
         *  Methods with PostSharp Aspects applied.
         * 
         **************************************************************************************************/


        [Trace("Test Category")]
        private static void Method1()
        {
            Method2();
        }

        [Trace("Test Category")]
        private static void Method2()
        {
            Method3();
        }

        [TraceForPerformanceAttribute]
        private static void Method3()
        {
            Thread.Sleep(10);
        }

        [TraceForPerformanceAttribute]
        private static int Factorial(int i)
        {
            if (i <= 1 && i >= -1) return i;
            if (i < 0)
            {
                return i * Factorial(i + 1);
            }
            else
            {
                return i * Factorial(i - 1);
            }
        }
    }
}
